<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);


define('EXT',              '.php');
define('DS',               DIRECTORY_SEPARATOR);
define('BASE_DIR',         dirname(__FILE__) . DS);
define('SYSTEM_DIR',       BASE_DIR . 'system' . DS);
define('EXTENSION_PREFIX', 'MY_');
define('EXTENSION_DIR',    BASE_DIR . 'extensions' . DS);
define('APPLICATION_DIR',  BASE_DIR . 'application' . DS);
define('TEMPLATE_DIR',     BASE_DIR . 'application' . DS . 'view' . DS);

include_once SYSTEM_DIR . 'functions' . DS . 'common' . EXT;
set_error_handler('php_error');
load_core('loader');
load_core('controller');

list($class, $method, $params) = url_route();
if ( ! $class) $class = 'test';
if ( ! $method) $method = 'say';

if (file_exists(APPLICATION_DIR . 'controller' . DS . $class . EXT))
{
	include APPLICATION_DIR . 'controller' . DS . $class . EXT;
} 
if ( ! class_exists($class) || ! in_array($method, get_class_methods($class)))
{
	system_error();
}

$object = new $class;
call_user_func_array(array($object, $method), $params);